package org.hy.service.group;

import java.util.List;

import org.hy.domain.group.Group;
import org.hy.persistence.group.GroupMapper;
import org.hy.util.AppConstant;
import org.hy.util.Pager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class GroupServiceImpl implements IGroupService {

	@Autowired
	private GroupMapper groupMapper;

	@Override
	public List<Group> listRecentGroup(int page, int size) {
		int offset = Pager.getOffset(page, size);
		return groupMapper.findGroupByTimeline(offset, size);
	}
	

	@Override
	public int addGroup(Group group) {
		int ret = 0;
		if(group != null){
			ret = groupMapper.insertGroup(group);
		}
		return ret;
	}

	@Override
	public int updateGroup(Group group) {
		int ret = 0;
		if(group != null){
			ret = groupMapper.updateGroup(group);
		}
		return ret;
	}

	@Override
	public int deleteGroup(int id) {
		return groupMapper.deleteGroup(id);
	}

	@Override
	public Group findGroupById(int id) {
		return groupMapper.findGroupById(id);
	}


	@Override
	public List<Group> searchGroupById(int id, int page, int size) {
		// TODO Auto-generated method stub
		return null;
	}
	
	@Override
	public int countGroupById(int id){
		return 0;
	}
	
	@Override
	public List<Group> searchGroupByName(String name, int page, int size) {
		int offset = Pager.getOffset(page, size);
		return groupMapper.searchGroupByName(name, offset, size);
	}


	@Override
	public int countGroupByName(String name) {
		// TODO Auto-generated method stub
		return 0;
	}


	@Override
	public List<Group> findGroupByUid(int uid,int page,int size) {
		int offset = Pager.getOffset(page, size);
		return groupMapper.findGroupByUid(uid, offset, size);
	}
	
	@Override
	public int countGroupByUid(int uid) {
		return groupMapper.countGroup(uid);
	}
	
}
